package com.lc202406;

public class Solution1816 {
    public String truncateSentence(String s, int k) {
        String res = "";
        int length = s.length();
        int cnt = 0;
        for (int i = 0; i < length; i++) {
            char str = s.charAt(i);
            if (str == ' ') {
                cnt++;
            }
            if (cnt == k) {
                return res;
            }
            res += str;
        }
        return res;
    }
}
